package modelLayer;

import java.util.ArrayList;

public class SaleLinesItem  {
	
		private ArrayList<Product> productCollection;
		private Product product;
		private String name;
		private String id;
		private String measure;
		private double quantity;
		private double price;
		private double buyQuantity;

		/*
		 * if it is not collection
		 */
	public SaleLinesItem(Product product) {
		
		this.setProduct(product);
		name = product.getName();
		id = String.valueOf(product.getId());
		buyQuantity = 0;
		
	}
	public SaleLinesItem(String ID, String name) {
		productCollection = new ArrayList<Product>();
		this.name = name;
		id = ID;
		buyQuantity = 0;
		measure = "piece";
		for(Product prod: productCollection){
			price = price + prod.getPrice();
			if(quantity>product.getQuantity()||quantity == 0)quantity = product.getQuantity();
		}
	}
	public String toStrings() {
		return "SaleLines" + getProduct().toString();
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "SaleLinesItem [productCollection=" + productCollection
				+ ", name=" + name + ", id=" + id + ", measure=" + measure
				+ ", quantity=" + quantity + ", price=" + price + "]";
	}
	public String save(){
		if(getItemCollection() != null) return 7+","+name+","+price+","+quantity+","+measure+","+id+","+product;
		else return "";
	}
	public String getID(){
		return id;
	}
	public void addToCollection(Product product, String name){
		productCollection.add(product);
	}
	public String getMeasure() {
		return measure;
	}
	public void setMeasure(String measure) {
		this.measure = measure;
	}
	public double getPrice() {
		return price;
	}
	public double getQuantity() {
		return quantity;
	}
	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public ArrayList<Product> getItemCollection() {
		return productCollection;
	}
	//manager chooses if the product will be sold as collection or not
	public void addItem(Product item){
		productCollection.add(item);
	}
	public Product getProduct(){
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	/**
	 * @return the productCollection
	 */
	public ArrayList<Product> getProductCollection() {
		return productCollection;
	}
	/**
	 * @param productCollection the productCollection to set
	 */
	public void setProductCollection(ArrayList<Product> productCollection) {
		this.productCollection = productCollection;
	}
	
	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	/**
	 * @return the buyQuantity
	 */
	public double getBuyQuantity() {
		return buyQuantity;
	}
	/**
	 * @param buyQuantity the buyQuantity to set
	 */
	public void setBuyQuantity(double buyQuantity) {
		this.buyQuantity = buyQuantity;
	}
	


}
